package com.company.project;

import java.util.Arrays;
import java.util.Map;

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.session.config.annotation.web.http.EnableSpringHttpSession;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.handler.AbstractHandlerMethodMapping;
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;

//@SpringBootApplication注解等价于以默认属性使用@Configuration，@EnableAutoConfiguration和@ComponentScan
@SpringBootApplication
public class Application {
	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
	}
	
	
	@Bean
    public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
        return args -> {

            System.out.println("Let's inspect the beans provided by Spring Boot:");

            String[] beanNames = ctx.getBeanDefinitionNames();
            Arrays.sort(beanNames);
            for (String beanName : beanNames) {
                System.out.println(beanName);
            }
            
            try {
            	AbstractHandlerMethodMapping<RequestMappingInfo> objHandlerMethodMapping = 
                		(AbstractHandlerMethodMapping<RequestMappingInfo>)ctx
                		.getBean("requestMappingHandlerMapping");  
                Map<RequestMappingInfo, HandlerMethod> mapRet = objHandlerMethodMapping.getHandlerMethods();
                for(Map.Entry<RequestMappingInfo, HandlerMethod> item : mapRet.entrySet()){  
                	RequestMappingInfo key=item.getKey();  
                    Object value=item.getValue();  
                  System.out.println("key:"+key+"  "+"value:"+value);  
                }  
            }catch (Exception e) {
				// TODO: handle exception
			}
            
        };
    }
}
